package slim3.demo.controller.tpe;


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.TimeZone;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;


public class RevisedFlightController extends Controller {



//    public static void main(String[] argv) throws Exception{
//        
//        ReadXMLFile test = new ReadXMLFile();
//        ArrayList<FlightBean> beans = test.getKNH();
//        ArrayList<FlightBean> beans = test.getMFKandLZN();
//        
//        for (int i=0; i<beans.size(); i++) {
//            System.out.println(beans.get(i));
//        }
//        
//    }
    
    @Override
    public Navigation run() throws Exception {

        ReadHTMLFile read = new ReadHTMLFile();
        ArrayList<FlightBean> beans = read.getRevisedFlightInformation();
        requestScope("flightlist", beans);
        
        //time
        Date date = new Date();
        DateFormat secondFormat = new SimpleDateFormat("yyyy M d HH mm ss");
        TimeZone secondTime = TimeZone.getTimeZone("Asia/Taipei");
        secondFormat.setTimeZone(secondTime);
        
        String t = secondFormat.format(date);
        
        String [] ts = t.split(" ");
        
        String year = ts[0];
        int temp = Integer.valueOf(year);
        temp = temp - 1911;
        year = temp + "";
        
        String month = ts[1];
        String day = ts[2];
        String hour = ts[3];
        String minute = ts[4];
        String second = ts[5];
                
        requestScope("year", year);
        requestScope("month", month);
        requestScope("day", day);
        requestScope("hour", hour);
        requestScope("minute", minute);
        requestScope("second", second);
        
        
        //airline info
//        InfoBox info = new InfoBox();
//        String infoAll = info.getBR();
//        requestScope("infoAirline", infoAll);
                
        return forward("/tpe/revised-flight.jsp");
    }
}